#+TITLE: Some Basic Defuns
#+AUTHOR:Joshua Branson
#+LATEX_HEADER: \usepackage{lmodern}
#+LATEX_HEADER: \usepackage[QX]{fontenc}


* lexical binding
  :PROPERTIES:
  :ID:       c901c3d8-a46e-4b21-9105-482ab7b8ef16
  :END:

#+BEGIN_SRC emacs-lisp
;; -*- lexical-binding: t; -*-
#+END_SRC

* defuns
** COMMENT bbdb interfers with helm-mode
   :PROPERTIES:
   :ID:       b1333b3c-9345-4d66-9454-2f18db07f4e9
   :END:

   #+BEGIN_SRC emacs-lisp
     (defun my/bbdb-create ())
   #+END_SRC
** open some various files
:PROPERTIES:
:ID:       8fc8b429-13ce-4435-a491-520934031b33
:END:

#+BEGIN_SRC emacs-lisp

(defun my/gtd ()
  "This command opens ~/things_to_do.org"
  (interactive)
  (find-file "~/prog/org/gtd.org"))

(defun my/init.el ()
  "init-file opens ~/.emacs"
  (interactive)
  (find-file "~/.config/emacs/init.el"))

(defun my/init-evil ()
  "loads my viper initialization file"
  (interactive)
  (load "~/.config/emacs/lisp/init-evil.el")
  (find-file "~/.config/emacs/lisp/init-evil.el"))

(defun rc.lua ()
  "This command opens ~/.config/awesome/rc.lua"
  (interactive)
  (find-file "~/.config/awesome/rc.lua"))

(defun emacs.texi ()
  "This command opens ~/manuals/cheatsheats/emacs.texi"
  (interactive)
  (find-file "~/manuals/cheatsheats/emacs.texi"))

(defun gawk.texi ()
  "This command opens ~/manuals/cheatsheats/gawk.texi"
  (interactive)
  (find-file "~/manuals/cheatsheats/gawk.texi"))

(defun systemd.texi ()
  "This command opens ~/manuals/systemd.texi"
  (interactive)
  (find-file "~/manuals/systemd.texi"))

#+END_SRC

** testing awesome
:PROPERTIES:
:ID:       a9ab9229-2021-4f38-ba51-fc6b49f6185d
:END:

#+BEGIN_SRC emacs-lisp
(defun test-awesome ()
  "this run /home/joshua/programming/bash/test-awesome.bash"
  (interactive)
  (start-process "testing-awesome" "test-of-awesome" "test-awesome.bash"))
#+END_SRC

** sudo find file
:PROPERTIES:
:ID:       030e5dcb-1c1c-4e1e-ae2f-cff25835c885
:END:

#+BEGIN_SRC emacs-lisp
(defun sudo-find-file ()
  "Like find file, but opens the file as root."
  (interactive)
  (interactive "FSudo Find File: ")
  (let ((tramp-file-name (concat "/sudo::" (expand-file-name file-name))))
    (find-file tramp-file-name)))

(defun find-file-sudo (file-name)
  "Like find file, but opens the file as root."
  (interactive)
  (sudo-file-file))
#+END_SRC
** Hurd view file in browser
:PROPERTIES:
:ID:       737e490a-0a38-419c-9c81-fd9ba4590f24
:END:
#+BEGIN_SRC emacs-lisp
  (defun view-hurd-file-in-browser ()
    "View this file in the browser"
    (interactive)
    (let [file (buffer-file-name)]))


#+END_SRC
** COMMENT

#+BEGIN_SRC emacs-lisp
(defun save-this-buffer-to-portfolio-site ()
  "Write this buffer to to my portfolio site"
  (interactive)
  ;; Take the current file and save it on the live server
  (setq current-directory
        (s-chop-prefix "Directory " (pwd)))
  (write-file "/ssh:jbranso_portfolio91@ssh.phx.nearlyfreespeech.net:/home/public/")
  ;;Take the current file and save it locally, that way, after I'm done saying the local file
  ;; to the server, pwd is still ~/programming/soihub
  (write-file current-directory))

(defun purdue-delete-this-buffer-from-dev-server ()
  "Remove this file to the purdue dev server."
  (interactive)
  (require 's)
  (let (remote-file-path remote-dir local-file)
    (setq local-file buffer-file-name)
    (setq remote-dir "/ssh:jbranso@dev.www.purdue.edu:/var/www/html/root/honorscollege/")
    (setq remote-file-path (concat
                            remote-dir
                            (s-chop-prefix "/home/joshua/honorscollege/" buffer-file-name)))
    (delete-file remote-file-path)))
#+END_SRC


#+BEGIN_SRC emacs-lisp
(defun purdue-deploy-to-dev-server ()
  "Rsynce my project to purdue's dev server."
  (interactive)
  (let (remote-file  remote-file-prefix)
    (setq remote-file-prefix "/ssh:jbranso@dev.www.purdue.edu:/home/users/jbranso/HTML/honorscollege/")
    (setq (concat remote-file (s-chop-prefix "/srv/http/honorscollege/" buffer-file-name)))
    (print remote-file)
    ;; (write-file remote-file)
    ;;(write-file local-file)
    )
  ;; (start-process "rsync-purdue" "*Purdue Deploy*" "rsync"
  ;;                ;; be verbose
  ;;                "-v "
  ;;                ;; recursive into directories
  ;;                "-r "
  ;;                "/srv/http/honorscollege/"
  ;;                "jbranso@dev.www.purdue.edu:/var/www/html/root/honorscollege/")
  ;; (let ((password (read-string "Enter your password: ")))
  ;;   (process-send-string "rsync-purdue" password))
  ;; (split-window-below)
  ;; (windmove-down)
  ;; (switch-to-buffer "rsync-purdue")
  )

(defun org-babel-strip-php-from-sql-block ()
  "Cleans up a sql statement from
   $sql  = 'SELECT * ';
   $sql .= 'FROM USERS ';
   $sql .= 'WHERE 1';
   into
   SELECT *
   FROM USERS
   WHERE 1 "
  (interactive)
  ;; let's first move to the top of the buffer
  (beginning-of-buffer)
  ;; now move point forward to the first char in the buffer
  (while (re-search-forward "\";" nil t)
    (replace-match ""))
  (while (re-search-forward "\$sql.*=.*?" nil t)
    (replace-match ""))
  (while (re-search-forward "\$sql.*\.=.*?" nil t)
    (replace-match ""))
  (while (re-search-forward "\$sql.*=.*\"" nil t)
    (replace-match "")))
#+END_SRC

** provide this file
:PROPERTIES:
:ID:       e1e2bd94-8495-4a22-825b-9e8809cb8279
:END:
   #+BEGIN_SRC emacs-lisp
   (provide 'init-defuns)
   #+END_SRC
